var pageX,pageX2;
Page({

  /**
   * 页面的初始数据
   */ 
  data: {
    num: 0,
    num2: 0,
    typeList: [
    
    ],
    brandList: [],
    startR: 0,
    endR: 10000,
    startE: 0,
    endE: 10000,
    minX: 0,
    carType:'',
    categoryId:''
  },

  // 切换类名on(车型)
  tab: function (e) {
    const eIndex = e.currentTarget.dataset.index;
    var carType = e.currentTarget.dataset.value
    if(carType=='全部'){
        carType=''
    }
    this.setData({
      num: eIndex,
      carType: carType
    });
  },

  // 切换类名on(品牌)
  tab2: function (e) {
    const eIndex = e.currentTarget.dataset.index;
    this.setData({
      num2: eIndex,
      categoryId: e.currentTarget.dataset.value
    });
  },
  moveEvent: function (e) {
    pageX = e.touches[0].pageX - wx.getSystemInfoSync().screenWidth / 750 * 44;
    if (pageX < 0) {
      pageX = 0;
    }
    if (pageX > this.data.maxX) {
      pageX = this.data.maxX;
    }
    this.setData({
      startE: parseInt(10000 * pageX / this.data.maxX)
    })

    if (this.data.startE > this.data.endE) {
      this.setData({
        startR: this.data.endE,
        endR: this.data.startE
      })
    } else {
      this.setData({
        startR: this.data.startE,
        endR: this.data.endE
      })
    }
  },

  moveEvent2: function (e) {
    pageX2 = e.touches[0].pageX - wx.getSystemInfoSync().screenWidth / 750 * 44;
    // console.log(e.touches[0].pageX)
    if (pageX2 < 0) {
      pageX2 = 0;
    }
    if (pageX2 > this.data.maxX) {
      pageX2 = this.data.maxX;
    }
    this.setData({
      endE: parseInt(10000 * pageX2 / this.data.maxX)
    }) 
    if (this.data.startE > this.data.endE) {
      this.setData({
        startR: this.data.endE,
        endR: this.data.startE
      })
    } else {
      this.setData({
        startR: this.data.startE,
        endR: this.data.endE
      })
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      maxX: wx.getSystemInfoSync().screenWidth / 750 * 662
    })
    this.loadCategory()
    this.loadCarType()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: '琼崖租车',
      path: '/pages/index/index'
    }
  },
  confirmSelect:function(){
    wx.redirectTo({
      url: '../self-driv/self-driv?carType=' + this.data.carType + '&categoryId=' + this.data.categoryId + '&startPrice=' + this.data.startR + '&lastPrice=' + this.data.endR
    })
  },
  loadCategory:function(){
    let that = this
    //加载推荐商品
    wx.request({
      url: 'https://small.qiongyazuche.com/sunday/small/product/category/select',
      method: 'POST',
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      data: {
        
      },
      success: function (res) {

        var categorys=res.data.result
        var brandList=new Array()
        var item={ name: '全部', image: '', id:''}
        brandList.push(item)
        for(var i=0;i<categorys.length;i++){
          var category=categorys[i]
            item={ name: category.name, image: category.image, id: category.id}
            brandList.push(item)
        }
        that.setData({
          brandList: brandList
        })
    
      }
    })
  },
  loadCarType:function(){
       let that = this
       //加载推荐商品
       wx.request({
            url: 'https://small.qiongyazuche.com/ace/system/dictionary/getDictionaryByKey',
            method: 'POST',
            header: {
                 "Content-Type": "application/x-www-form-urlencoded"
            },
            data: {
                 'key':'carType'     
            },
            success: function (res) {
                 var cartypes = res.data
                 var typeList = new Array()
                 var item = '全部'
                 typeList.push(item)
                 for (var i = 0; i < cartypes.length; i++) {
                      var cartype = cartypes[i]
                      item = cartype.name
                      typeList.push(item)
                 }
                 that.setData({
                      typeList: typeList
                 })

            }
       })
  }
})